package cn.edu.hqu.cst.android.ls.eventmechanism;

import android.annotation.SuppressLint;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;
import android.widget.Toast;
import android.content.Intent;

import androidx.appcompat.app.AppCompatActivity;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;



public class MainActivity extends AppCompatActivity implements View.OnClickListener {

    Button bn1, bn2, bn4, bn5,bn7,bn8;

    @BindView(R.id.textView)
    TextView textView;
  //  @BindView(R.id.show)
    EditText show;

    @BindView(R.id.bn6)
    Button bn6;
    //@BindView(R.id.bn7)
    //Button bn7;
   // @BindView(R.id.bn8)
   // Button bn8;



    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
       // ButterKnife.bind(this);


        bn1 = (Button) findViewById(R.id.bn1);
        bn2 = (Button) findViewById(R.id.bn2);
        bn4 = (Button) findViewById(R.id.bn4);
        show = (EditText) findViewById(R.id.show);
        //1直接使用activity作为监听器
        bn1.setOnClickListener((View.OnClickListener) this);
        //匿名内部类作为监听器
        bn2.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                show.setText("内部匿名类作为监听器！");
            }
        });
        //1内部类作为监听器1
        bn4.setOnClickListener(new MyclickListener());
        //外部类作为监听器；
        bn5 = (Button) findViewById(R.id.bn5);
        bn5.setOnClickListener(new Outside() {
            @SuppressLint("WrongConstant")
            @Override
            public void onClick(View v) {
                super.onClick(v);
                Toast.makeText(MainActivity.this, "外部类作为监听器！", 1).show();
            }
        });
        //点击bn7，跳转系统信息
        bn7 = (Button) findViewById(R.id.bn7);
        bn7.setOnClickListener((new View.OnClickListener(){
            @Override
            public void onClick(View v){
                Intent i = new Intent(MainActivity.this , Main2Activity.class);
                startActivity(i);
            }
        }));
        //点击bn8，进入模拟进度条
        bn8 = (Button) findViewById(R.id.bn8);
        bn8.setOnClickListener((new View.OnClickListener(){
            @Override
            public void onClick(View v){
                Intent i = new Intent(MainActivity.this , Main3Activity.class);
                startActivity(i);
            }
        }));

    }
  //Butterknife作为监听器
   @SuppressLint("WrongConstant")
   @OnClick(R.id.bn6)
    public void onViewClicked(View view) {

        switch (view.getId()) {
       case R.id.bn6:
           Toast.makeText(MainActivity.this, "Butterknife作为监听器！", 1).show();
           break;
   }
        }



    //2内部类作为监听器；
    class MyclickListener implements View.OnClickListener {
        @Override
        public void onClick(View v) {
            show = (EditText) findViewById(R.id.show);
            show.setText("内部类作为监听器！");
        }
    }


    //直接绑定按钮作为监听器
    public void clickHandler(View v) {
        show = (EditText) findViewById(R.id.show);
        show.setText("直接绑定按钮作为监听器！");

    }

    //2直接使用activity作为监听器
    @Override
    public void onClick(View v) {
        show.setText("Activity作为监听器！");
    }
}

